Skip to content

fix(rpc): emit canonical block hash in newHeads subscription#1214

Open
puneet2019 wants to merge 2 commits into
cosmos:mainfrom
puneet2019:fix/newheads-canonical-hash
Open

fix(rpc): emit canonical block hash in newHeads subscription#1214
puneet2019 wants to merge 2 commits into
cosmos:mainfrom
puneet2019:fix/newheads-canonical-hash

Conversation

@puneet2019

Copy link
Copy Markdown

Description

eth_subscribe("newHeads") publishes the derived Ethereum-header hash (keccak(RLP(eth header))), but eth_getBlockByNumber / eth_getBlockByHash report and resolve by the CometBFT block hash (RPCMarshalHeader sets "hash" to it; GetBlockByHash looks it up via CometBFT). So a newHeads notification's hash doesn't match the same block from eth_getBlockByNumber, and passing it to eth_getBlockByHash / eth_getLogs({blockHash}) returns "block not found".

This completes #725 — that PR aligned the JSON-RPC responses and added the canonical hash to the stream header (stream.RPCHeader.Hash = data.BlockID.Hash), but the WebSocket subscribeNewHeads handler was left emitting header.EthHeader.

Change (rpc/websockets.go):

- Result: header.EthHeader,
+ Result: rpctypes.RPCMarshalHeader(header.EthHeader, header.Hash.Bytes()),

RPCMarshalHeader returns the full header map with the canonical "hash", so newHeads now matches eth_getBlockByNumber.

How to review / test

newHeads.hash now equals eth_getBlockByNumber(<same height>).hash, and that hash resolves via eth_getBlockByHash / eth_getLogs({blockHash}) (previously "block not found"). Verified end-to-end in a downstream chain adopting cosmos/evm/rpc (WS eth_subscribe e2e green). Happy to add an integration assertion if preferred.

Author Checklist

🤖 Generated with Claude Code

@puneet2019 puneet2019 requested a review from a team as a code owner July 2, 2026 15:08
@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

Signed-off-by: puneetmahajan <59960662+puneet2019@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@puneet2019 puneet2019 force-pushed the fix/newheads-canonical-hash branch from d004317 to 81c4558 Compare July 2, 2026 15:09
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.99%. Comparing base (7c492af) to head (f7760bb).

Files with missing lines Patch % Lines
rpc/websockets.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1214      +/-   ##
==========================================
- Coverage   67.02%   66.99%   -0.03%     
==========================================
  Files         320      320              
  Lines       23438    23438              
==========================================
- Hits        15709    15702       -7     
- Misses       6572     6578       +6     
- Partials     1157     1158       +1     
Files with missing lines Coverage Δ
rpc/websockets.go 16.42% <0.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants